import {
  Button,
  Card,
  Icon,
  Input,
  InputNumber,
  message,
  Select,
  Spin,
  Table,
  Tooltip,
  Popconfirm
} from "antd";
import { connect } from "dva";
import { routerRedux } from "dva/router";
import moment from "moment";
import PropTypes from "prop-types";
import React, { PureComponent } from "react";
import enums from "./enums";
import PateoAuthButtons from "@/common/PateoAuthButtons/PateoAuthButtons";
import AddModal from "./addModal";
import BacthChangeStateModal from "./bacthChangeStateModal";
import BatchImportModal from "./batchImportModal";
import BatchSearchModal from "./batchSearchModal";
import SearchAdtional from "./component/searchAdtional/index";
import data from "./data";
import ExportTaskModal from "./exportTaskModal";
import FieldModal from "./fieldModal";
import styles from "./index.less";
import { transferOption } from "@/utils/common";
import MsgRulerModal from "./msgRulerModal";
import MovingCarModal from "./movingCarModal";
import DealerRiskManageModal from "./dealRiskManageModal";
import RiskLogModal from "./riskLogModal";
import ConfigModal from './configModal';
import { getDicByKey, getDictOptionsByCode } from '@/support/common';
import { SettingOutlined } from '@ant-design/icons';
const { Option } = Select;
const riskStatusEnum = {
  1: '锁车',
  2: '跛行',
}
const toLine = (name) => {
  return name.replace(/([A-Z])/g, "_$1").toLowerCase();
};
// 下划线转驼峰
function toCamel(str) {
  return str.replace(/([^_])(?:_+([^_]))/g, function ($0, $1, $2) {
    return $1 + $2.toUpperCase();
  });
}

@connect((state) => ({
  menu: state.menu,
  creditCar: state.creditCar,
  merchantsData: state.menu.merchantsData
}))
export default class CreditCar extends PureComponent {
  static contextTypes = {
    authButton: PropTypes.array,
    dicData: PropTypes.any,
  };

  state = {
    batchSearchModalVisible: false,
    addModalVisible: false,
    batchImportModalVisible: false,
    bacthChangeStateModalVisible: false,
    exportTaskVisible: false,
    batchSelectData: [],
    tableData: [],
    vin: undefined,
    seriesId: undefined,
    symbol: undefined,
    last7MileageStart: 0,
    last7MileageEnd: 0,
    merchantName: undefined,
    creditType: undefined,
    curPage: 1,
    pageSize: 10,
    total: 0,
    tableLoading: false,
    exportLoading: false,
    seriesList: [],
    bacthChangeStateModalData: [],
    taskId: undefined,
    taskType: undefined,
    batchAddTemplateFileUrl: "",
    batchSearchTemplateFileUrl: "",
    orgList: [],
    tboxRouseloading: false,
    tboxRouseCount: 35,
    fieldList: [], // 列表可显示动态字段
    fieldMore: [], // 更多筛选可以使用的字段
    fieldAdd: [], // 新增可用字段
    fieldColumns: [],

    tableColumns: [], //动态列表clonmn

    checked: [],
    currentSearchMode: "1", // 1: 外部搜索   2，更所筛选搜索

    ruleList: [],
    msgRuleModalVisible: false,
    ruleListSelectedRecord: {},
    ruleListType: 1,
    riskvin: undefined,
    dealRiskManageModalVisible: false,//经销商风险管理
    riskLogModalVisible: false,//风控日志
    creditTypeOptions: [],
  };

  handlemsgRemove = (record) => {
    //解除车机告警
    const { dispatch } = this.props;
    let params = {
      businessCode: "credit-car-log",
      vin: record.vin,
    };

    dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/ivi/warn/remove",
        ...params,
      },
      callback: (response) => {
        if (response.statusCode === "0") {
          message.success("修改成功");
          this.handleTableNewData();
        } else {
        }
      },
    });
  };
  handleWarnMsg = (record) => {
    //车机告警--已配置车机告警规则，直接开启
    let params = {
      businessCode: "credit-car-log",
      vin: record.vin,
      iviNoticeUuid: "",
    };
    this.props.dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/ivi/warn",
        ...params,
      },
      callback: (response) => {
        if (response.statusCode === "0") {
          message.success("发送成功");
          this.handleTableNewData();
        } else {
        }
      },
    });
  };
  // 查询当前商户有效车机告警规则列表
  handlemsgRulerList = (record, type) => {
    let params = {};
    if (type == 1) {
      // 正常行驶
      if (record.riskStatus == 0) {
        params = {
          showTypes: [1, 2, 3],
          useType: 3,
        };
      } else if (record.riskStatus == 1) {
        params = {
          showTypes: [1, 2, 3],
          useType: 2,
        };
      } else if (record.riskStatus == 2) {
        params = {
          showTypes: [1, 2, 3],
          useType: 1,
        };
      } else {
        params = {
          showTypes: [1, 2, 3],
          useType: 3,
        };
      }
    } else if (type == 2) {
      //锁车
      params = {
        showTypes: [1, 2, 3],
        useType: 2,
      };
    } else if (type == 3) {
      params = {
        showTypes: [1, 2, 3],
        useType: 1,
      };
    }
    Object.assign(params, { isEnable: 1 })//1已生效 2停用
    this.props.dispatch({
      type: "creditCar/postObjWithRes",
      payload: {
        url: "/mscreditbusiness/iviNotice/list",
        ...params,
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          this.setState({
            ruleList: response.data,
            msgRuleModalVisible: true,
            ruleListSelectedRecord: record,
            ruleListType: type,
          });
        } else {
        }
      },
    });
  };

  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'menu/getMerchantsData',
    });
    this.getDic();
    this.handleTableNewData();//获取列表数据
    this.getFieldList();// 获取列表字段listclumon
    this.handleGetBatchAddTemplateFileUrl();//获取批量导入授信车模板
    this.handleGetBatchSearchTemplateFileUrl();//获取批量导入VIN号模板-搜索框
    this.handleGetFieldList();// 获取新增、更多筛选条件的字段clumon 
    this.handleGetSeriesByBrandCode();//获取车系数据
    this.handleGetOrgList();//获取当前商户车辆所属公司及下层公司
  }
  getDic = () => {
    const { menu: { dicData } } = this.props;
    const typeOption = getDictOptionsByCode(dicData, 'creditType');
    this.setState({
      creditTypeOptions: typeOption.map(e => ({
        label: e.label,
        value: e.value,
      })),
    })
  }
  addPreinstall = (columns) => {
    return columns.map((i) => {
      const sameTitle = columns.some(
        (j) => j.name === i.name && i.fieldId !== j.fieldId
      );
      if (sameTitle && i.fieldId) {
        i.name = `${i.name}(预设)`;
      }
      return i;
    });
  };
  getFieldList = () => {
    // 获取列表字段
    this.props.dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/credit/merchant/field/scenelist?menu=credit&scene=list",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          if (response.data && response.data.length > 0) {
            const fieldData = response.data;
            let arr = [];
            this.addPreinstall(response.data).map((item) => {
              if (item.type === 4) {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (typeof text == "number") {
                      return text ? moment(text).format("YYYY-MM-DD") : "";
                    } else {
                      return text
                        ? moment(text, "YYYY-MM-DD").format("YYYY-MM-DD")
                        : "";
                    }
                  },
                });
              } else if (item.type === 5) {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (typeof text == "number") {
                      return text ? moment(text).format("HH:mm:ss") : "";
                    } else {
                      return text
                        ? moment(text, "HH:mm:ss").format("HH:mm:ss")
                        : "";
                    }
                  },
                });
              } else if (item.type === 6) {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (typeof text == "number") {
                      return text
                        ? moment(text).format("YYYY-MM-DD HH:mm:ss")
                        : "";
                    } else {
                      return text
                        ? moment(text, "YYYY-MM-DD HH:mm:ss").format(
                          "YYYY-MM-DD HH:mm:ss"
                        )
                        : "";
                    }
                  },
                });
              } else if (item.name === "是否支持跛行") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    return text == 1 ? "是" : "否";
                  },
                });
              } else if (item.name === "车辆预警状态") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (text == "0") {
                      return "未预警";
                    } else if (text == "1") {
                      return "预警";
                    } else {
                      return text;
                    }
                  },
                });
              } else if (item.name === "还款状态") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (text == "0") {
                      return "正常还款";
                    } else if (text == "1") {
                      return "已逾期";
                    } else if (text == "2") {
                      return "已结清";
                    } else if (text == "3") {
                      return "融资已到期";
                    } else {
                      return "未知";
                    }
                  },
                });
              } else if (item.name === "车辆风控状态") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text, record) => {
                    if (text == 0) {
                      return "正常行驶";
                    } else if (text == 1) {
                      return "锁车";
                    } else if (text == 2) {
                      return "跛行";
                    } else {
                      return text;
                    }
                  },
                });
              } else if (item.name === "车机告警类型") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (text == 0) {
                      return "暂不支持";
                    } else if (text == 1) {
                      return "不可配置";
                    } else if (text == 2) {
                      return "可配置";
                    } else {
                      return text;
                    }
                  },
                });
              } else if (item.name === "车机告警状态") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (text == 0) {
                      return "正常";
                    } else if (text == 1) {
                      return "车机告警";
                    } else {
                      return ' ';
                    }
                  },
                });
              } else if (item.name === "实车当前状态") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text) => {
                    if (text == 0) {
                      return "正常";
                    } else if (text == 1) {
                      return "锁车";
                    } else if (text == 2) {
                      return "跛行";
                    } else if (text == 3) {
                      return "待车辆反馈";
                    } else {
                      return "待车辆反馈";
                    }
                  },
                });
              } else if (item.name === "授信类型") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: text => {
                    if (text == null) {
                      return '';
                    }
                    return getDicByKey(this.context.dicData, `creditType`, text.toString());
                  },
                });
              } else if (item.name === "经销商名称") {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                  render: (text, record) => {
                    if (text) {
                      return <a onClick={() => this.dealerRiskManage(record)}>{text}</a>;
                    } else {
                      return '';
                    }
                  },
                });
              } else {
                arr.push({
                  title: item.name,
                  dataIndex: toCamel(item.column),
                  key: toCamel(item.column),
                });
              }
            });
            arr = arr.map((i) => {
              i.columnShow = true;
              return i;
            });
            this.setState({
              tableColumns: this.fieldModal.getTableColumns(arr),
            });
          }
        } else {
        }
      },
    });
  };
  openFieldModal = () => {
    this.fieldModal.open(this.state.tableColumns);
  };
  loop = (arr) => {
    let tree = JSON.parse(JSON.stringify(arr))
    let newData = []
    const expanded = datas => {
      if (datas && datas.length > 0) {
        datas.forEach(e => {
          newData.push({ sid: e.sid, name: e.orgName });
          expanded(e.children);
        })
      }
    };
    expanded(tree);
    return newData;
  }
  handleGetOrgList = () => {
    this.props.dispatch({
      type: "creditCar/getDataWithRes",
      payload: {
        url: "/org/tree",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          if (response.data && response.data.length > 0) {
            const newData = this.loop(response.data)
            this.setState({
              orgList: newData,
            });
          }
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };

  handleGetFieldList = () => {
    this.props.dispatch({
      // 更多筛选数据
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/credit/merchant/field/scenelist?menu=credit&scene=more",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          if (response.data && response.data.length > 0) {
            this.setState({
              fieldMore: this.addPreinstall(response.data),
            });
          }
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
    this.props.dispatch({
      // 新增
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/credit/merchant/field/scenelist?menu=credit&scene=add",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          if (response.data && response.data.length > 0) {
            this.setState({
              fieldAdd: this.addPreinstall(response.data),
            });
          }
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };

  handleGetBatchAddTemplateFileUrl = () => {
    this.props.dispatch({
      type: "creditCar/getData",
      payload: { url: '/common/template/detail', templateCode: 'creditCarBatchAdd' },
      callback: (res) =>
        this.setState({
          batchAddTemplateFileUrl: res.data ? res.data.templateUrl : "",
        }),
    });
  };

  handleGetBatchSearchTemplateFileUrl = () => {
    this.props.dispatch({
      type: "creditCar/getData",
      payload: { url: '/common/template/detail', templateCode: 'creditCarBatchSearch' },
      callback: (res) =>
        this.setState({
          batchSearchTemplateFileUrl: res.data ? res.data.templateUrl : "",
        }),
    });
  };

  handleGetSeriesByBrandCode = () => {
    this.props.dispatch({
      type: "creditCar/getDataWithRes",
      payload: { url: '/msdevice/base/vehicle/series/list' },
      callback: (response) => {
        this.setState({
          seriesList: (response.data ?? []).map(e => ({
            label: e.seriesName,
            value: e.seriesCode,
          })),
        });
      },
    });
  };
  handleTableNewData = () => {
    let params = [];
    const { curPage, pageSize, fieldColumns, currentSearchMode } = this.state;
    if (currentSearchMode == "1") {//外部搜索
      params = this.exChangeDefaultData().filter(
        (i) =>
          !(
            i.startVal === undefined ||
            i.startVal === null ||
            i.startVal === ""
          )
      );
    } else {
      params = fieldColumns;
    }
    this.props.dispatch({
      type: "creditCar/postObjWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/credit/page",
        curPage: curPage,
        pageSize: pageSize,
        conditions: params,
      },
      callback: (response) => {
        if (response && response.statusCode == "0" && response.data) {
          if (
            response.data.rows.length === 0 &&
            response.data.pagination.current > 1
          ) {
            this.setState(
              {
                curPage: 1,
                pageSize: 10,
              },
              () => {
                this.handleTableNewData();
              }
            );
          } else {
            this.setState({
              tableData: response.data.rows,
              total: response.data.pagination.total,
            });
          }
        } else {
          if (response.statusCode !== "0") {
            // message.error(response.statusMessage);
          }
        }
        this.setState({
          tableLoading: false,
        });
      },
    });
  };

  //点击批量导入授信车辆
  handleBatchimport = (msg) => {
    this.setState({
      batchImportModalVisible: true,
    });
  };

  //点击批量查询授信车辆
  handleBatchiSearch = (msg) => {
    this.setState({
      batchSearchModalVisible: true,
    });
  };

  //点击新增授信车辆
  handleAdd = (msg) => {
    this.setState({
      addModalVisible: true,
    });
  };

  //点击导出授信车辆
  handleExportCar = (msg) => {
    this.setState({
      exportLoading: true,
    });

    let params = [];
    const { curPage, pageSize, fieldColumns, currentSearchMode } = this.state;
    if (currentSearchMode == "1") {
      params = this.exChangeDefaultData().filter(
        (i) =>
          !(
            i.startVal === undefined ||
            i.startVal === null ||
            i.startVal === ""
          )
      );
    } else {
      params = fieldColumns;
    }

    this.props.dispatch({
      type: "creditCar/postObjWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/credit/exportTask",
        ...{
          conditions: params,
          curPage,
          pageSize,
        },
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("操作成功,请点击[任务中心]按钮查看处理进度!");
          this.setState({
            taskId: response.data.taskId,
            taskType: response.data.taskType,
          });
        } else {
          // message.error(response.statusMessage);
        }
        this.setState({
          exportLoading: false,
        });
      },
    });
  };

  //点击地图查看授信车辆
  handleCreditCarMap = () => {
    sessionStorage.setItem(
      "backPathMap",
      "/creditPlatform/creditCar"
    );
    sessionStorage.setItem("typeOption", JSON.stringify(this.state.creditTypeOptions));
    sessionStorage.setItem("isWarningCarMap", "");
    this.props.dispatch(
      routerRedux.push({
        pathname: "/creditPlatform/creditCarMap",
      })
    );
  };

  //点击导出任务
  handleExportTask = (msg) => {
    this.setState({
      exportTaskVisible: true,
    });
  };

  //点击批量修改授信车辆
  handleBacthChangeState = (msg) => {
    const { bacthChangeStateModalData } = this.state;
    this.setState({
      bacthChangeStateModalData: bacthChangeStateModalData,
      bacthChangeStateModalVisible: true,
    });
  };

  //点击详情
  handleDetail = (vin) => {
    sessionStorage.setItem("vin", vin);
    sessionStorage.setItem("typeOption", JSON.stringify(this.state.creditTypeOptions));
    sessionStorage.setItem(
      "backPath",
      "/creditPlatform/creditCar"
    );
    this.props.dispatch(
      routerRedux.push({
        pathname: "/creditPlatform/creditCarDetail",
      })
    );
  };

  //点击解除授信车辆
  handleRelieve = (vin, warnStatus) => {
    const { merchantsData } = this.props;
    const list = [vin];
    const url = merchantsData.type !== 1 ? "/mscreditbusiness/vehicle/credit/remove" : "/mscreditbusiness/vehicle/credit/relation/remove"
    this.handleDel(url, list)
    // if (warnStatus == 1) {
    //   let params = {
    //     businessCode: "credit-car-log",
    //     vin: vin,
    //   };
    //   if (merchantsData.type === 1) { // 持车机构不解除告警
    //     const url = "/mscreditbusiness/vehicle/credit/relation/remove";
    //     const list = [vin];
    //     this.handleDel(url, list)
    //   } else {
    //     this.props.dispatch({
    //       type: "creditCar/postDataWithRes",
    //       payload: {
    //         url: "/mscreditbusiness/vehicle/ivi/warn/remove",
    //         ...params,
    //       },
    //       callback: (response) => {
    //         if (response && response.statusCode == "0") {
    //           message.success("解除车机告警成功");
    //           const list = [vin];
    //           const { merchantsData } = this.props;
    //           const url = merchantsData.type !== 1 ? "/mscreditbusiness/vehicle/credit/remove" : "/mscreditbusiness/vehicle/credit/relation/remove"
    //           this.handleDel(url, list)
    //         } else {
    //           // message.error(response.statusMessage);
    //         }
    //       },
    //     });
    //   }
    // } else {
    //   const list = [vin];
    //   const url = merchantsData.type !== 1 ? "/mscreditbusiness/vehicle/credit/remove" : "/mscreditbusiness/vehicle/credit/relation/remove"
    //   this.handleDel(url, list)
    // }
  };
  handleDel = (url, list) => {
    this.props.dispatch({
      type: "creditCar/postListList",
      payload: {
        url: url,
        list,
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("解除授信成功");
          this.handleTableNewData();
        } else {
          message.error(response.statusMessage);
        }
      },
    });
  }
  //批量解除授信
  bathRelieve = () => {
    const { bacthChangeStateModalData } = this.state;
    if (bacthChangeStateModalData.length <= 0) {
      message.warning('请选择车辆！')
    }
    const list = bacthChangeStateModalData
    const { merchantsData } = this.props;
    const url = merchantsData.type !== 1 ? "/mscreditbusiness/vehicle/credit/remove" : "/mscreditbusiness/vehicle/credit/relation/remove"

    this.props.dispatch({
      type: "creditCar/postListList",
      payload: {
        url: url,
        list,
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("解除授信成功");
          this.setState({
            batchSelectData: [],
          })
          this.handleTableNewData();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  }
  handleSleep = async () => {
    await new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve();
      }, 5000);
    });
  };

  //点击TBOX唤醒
  handleTboxRouse = (vin) => {
    this.setState({
      tboxRouseloading: true,
    });
    this.props.dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/tbox/wake",
        vin: vin,
        businessCode: "credit-car-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("已经给该车辆发送远程唤醒指令");
          let tboxRouseCount = 35;
          let tboxRouseSearchCount = 3;
          this.timer = setInterval(() => {
            tboxRouseCount--;
            this.setState({ tboxRouseCount });
            //请求详情接口
            if (tboxRouseCount <= 0) {
              this.setState({
                tboxRouseloading: false,
                tboxRouseCount: 35,
              });
              clearInterval(this.timer);
              message.error("TBOX没有被成功唤醒");
            }
          }, 1000);

          this.timer2 = setInterval(() => {
            tboxRouseSearchCount--;
            //请求详情接口
            this.props.dispatch({
              type: "creditCar/postDataWithRes",
              payload: {
                url: "/mscreditbusiness/vehicle/tbox/wake/result",
                vin: vin,
              },
              callback: (response) => {
                if (response && response.statusCode == "0") {
                  if (response.data) {
                    message.success("TBOX被成功唤醒");
                    this.handleTableNewData();
                    clearInterval(this.timer2);
                    clearInterval(this.timer);
                    this.setState({
                      tboxRouseloading: false,
                      tboxRouseCount: 35,
                    });
                  }
                } else {
                  // message.error(response.statusMessage);
                }
              },
            });

            if (tboxRouseSearchCount <= 0 || tboxRouseCount <= 0) {
              clearInterval(this.timer2);
            }
          }, 10000);
        } else {
          // message.error(response.statusMessage);
          this.setState({
            tboxRouseloading: false,
            tboxRouseCount: 35,
          });
        }
      },
    });
  };

  componentWillUnmount() {
    clearInterval(this.timer2);
    clearInterval(this.timer);
  }

  changeBacthChangeStateModalVisible = (flag) => {
    if (flag) {
      //TODO:请求接口刷新数据
      this.handleTableNewData();
      this.setState({
        bacthChangeStateModalVisible: false,
        bacthChangeStateModalData: [],
        batchSelectData: [],
      });
    } else {
      this.setState({
        bacthChangeStateModalVisible: false,
      });
    }
  };

  changeBatchImportModalVisible = (flag) => {
    if (flag) {
      //TODO:请求接口刷新数据
      this.setState({
        batchImportModalVisible: false,
      });
    } else {
      this.setState({
        batchImportModalVisible: false,
      });
    }
  };

  changeBatchSearchModalVisible = (flag) => {
    if (flag) {
      //TODO:请求接口刷新数据
      this.setState({
        batchSearchModalVisible: false,
      });
    } else {
      this.setState({
        batchSearchModalVisible: false,
      });
    }
  };

  changeAddModalVisible = (flag) => {
    if (flag) {
      //TODO:请求接口刷新数据
      this.handleTableNewData();
      this.setState({
        addModalVisible: false,
      });
    } else {
      this.setState({
        addModalVisible: false,
      });
    }
  };
  changeExportTaskModalVisible = (flag) => {
    if (flag) {
      //TODO:请求接口刷新数据
      this.setState({
        exportTaskVisible: false,
      });
    } else {
      this.setState({
        exportTaskVisible: false,
      });
    }
  };

  handleRowSelection = (selectedRowKeys, selectedRows) => {
    this.setState({
      batchSelectData: selectedRows,
      bacthChangeStateModalData: selectedRowKeys,
    });
  };

  handleReset = () => {
    this.setState(
      {
        curPage: 1,
        pageSize: 10,
        seriesId: undefined,
        vin: undefined,
        symbol: undefined,
        last7MileageStart: 0,
        last7MileageEnd: 0,
        merchantName: undefined,
        creditType: undefined,
        fieldColumns: [],
        currentSearchMode: "1",
      },
      () => {
        this.handleTableNewData();
        // this.SearchAdtionalRef.reset();
      }
    );
  };
  specialDataGenrator = () => {
    // 生成特殊字段
    return [
      {
        // 所属公司
        columnName: "vin",
        columnType: 1,
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
        filterType: 1,
      },
      {
        // 所属公司
        columnName: "company_name",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: this.state.orgList.map((i) => ({
            label: i.name,
            value: i.sid,
          })),
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
        filterType: 1,
      },
      {
        // 实车当前状态
        columnName: "vhl_current_status",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              value: 0,
              label: "正常",
            },
            {
              value: 1,
              label: "锁车",
            },
            {
              value: 2,
              label: "跛行",
            },
            {
              value: 3,
              label: "待车辆反馈",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
        filterType: 1,
      },
      {
        // 车系
        columnName: "series_name",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: this.state.seriesList,
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
        // filterTypeLock: true,
        // defaultField: true,
      },
      {
        columnName: "last7_mileage",
        columnType: 3,
        filter: undefined,
        startVal: undefined,
        endVal: undefined,
        filterType: "1",
      },
      {
        columnName: "limp_enable",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              value: "0",
              label: "不支持",
            },
            {
              value: "1",
              label: "支持",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
      {
        columnName: "warn_type",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              value: 0,
              label: "暂不支持",
            },
            {
              value: 1,
              label: "不可配置",
            },
            {
              value: 2,
              label: "可配置",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
      {
        columnName: "warn_status",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              value: 0,
              label: "正常",
            },
            {
              value: 1,
              label: "车机告警",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
      {
        columnName: "repayment_status",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              // 0-还款中；1-已逾期；2-已结清；3-融资已到期
              value: "0",
              label: "正常还款",
            },
            {
              value: "1",
              label: "已逾期",
            },
            {
              value: "99",
              label: "未知",
            },
            {
              value: "2",
              label: "已结清",
              hideInOption: true,
            },
            {
              value: "3",
              label: "融资已到期",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
      {
        columnName: "risk_warn_status",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              // 1：预警  0或null：未预警 ；
              value: "0",
              label: "未预警",
            },
            {
              value: "1",
              label: "预警",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
      {
        columnName: "engine_state",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              //  2-点火；0-熄火
              value: "0",
              label: "熄火",
            },
            {
              value: "2",
              label: "点火",
            },
            {
              value: "",
              label: "行驶中",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
      {
        columnName: "risk_status",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: [
            {
              //   0-正常行驶，1-锁车，2-跛行
              value: "0",
              label: "正常行驶",
            },
            {
              value: "1",
              label: "锁车",
            },
            {
              value: "2",
              label: "跛行",
            },
          ],
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
      {
        columnName: "credit_type",
        columnType: 2,
        extra: {
          selectType: 0,
          optionList: this.state.creditTypeOptions,
        },
        // filter: 9,
        startVal: undefined,
        endVal: undefined,
      },
    ];
  };

  exChangeDefaultData = () => {
    // 从外面带的属性
    const {
      vin,
      seriesId,
      symbol,
      last7MileageStart,
      last7MileageEnd,
      merchantName,
      creditType,
    } = this.state;
    return [
      {
        columnName: "vin",
        columnType: 1,
        filter: vin ? "1" : undefined,
        startVal: vin,
        endVal: undefined,
        filterType: "1",
      },
      {
        columnName: "company_name",
        columnType: 2,
        filter: merchantName ? "9" : undefined,
        startVal: merchantName,
        endVal: undefined,
        filterType: "1",
      },
      {
        columnName: "series_name",
        columnType: 2,
        filter: seriesId ? "9" : undefined,
        startVal: seriesId,
        endVal: undefined,
        filterType: "1",
      },
      {
        columnName: "last7_mileage",
        columnType: 3,
        filter: enums.comparison[symbol]
          ? enums.comparison[symbol].filter
          : undefined,
        startVal: symbol ? last7MileageStart : undefined,
        endVal: symbol ? last7MileageEnd : undefined,
        filterType: "1",
      },
      {
        columnName: "credit_type",
        columnType: 2,
        filter: creditType ? "9" : undefined,
        startVal: creditType ? creditType : undefined,
        endVal: undefined,
        filterType: "1",
      },
    ];
  };

  handleOpenSeachModal = () => {
    // 更所筛选
    const specialData = this.specialDataGenrator(); // 特殊字段，本地定义
    let exChangeData = this.exChangeDefaultData(); // 从外面带进来的值
    this.SearchAdtionalRef.modalShow(specialData, exChangeData);
  };

  handleSearch = () => {
    this.setState(
      {
        currentSearchMode: "1",
      },
      () => {
        this.handleTableNewData();
      }
    );
  };
  //移车管理
  handleMovingcar = (record) => {//0:未绑定  1：绑定
    if (record.isBind == 1) {
      this.props.dispatch({//获取车辆当前围栏信息
        type: 'creditCar/getDataWithRes',
        payload: {
          url: '/mscreditbusiness/vehicle/fence/info',
          vin: record.vin,
        },
        callback: (response) => {
          if (response.statusCode == '0') {
            this.props.dispatch({
              type: 'creditCar/getDataWithRes',
              payload: {
                url: '/electricfence/findfencebyall',
                dealerCode: response.data[0].dealerCode,
                orgId: record.orgId,
              },
              callback: (res) => {
                if (res.statusCode == '0') {
                  let data = {};
                  data['currentFenceInfo'] = { ...response.data[0] };
                  data['fenceList'] = [...res.data];
                  data['vin'] = record.vin;
                  this.movingModal.showData(data)
                }
              },
            });

          }
        },
      });
    } else {
      message.warning("请先关联围栏再进行移库/借车操作！")
    }
  };

  //点击经销商名称进入经销商风险管理页
  dealerRiskManage = (record) => {
    const { dispatch } = this.props
    //获取当前经销商风险额度
    dispatch({
      type: 'creditCar/postDataWithRes',
      payload: {
        url: '/mscreditbusiness/dealer/limit/get',  //  查询高风险经销商额度
        orgId: record.orgId,
        dealerCode: record.dealerCode
      },
      callback: (res) => {
        const { statusCode, data } = res;
        if (statusCode === '0') {
          this.setState({
            dealRiskManageModalVisible: true
          });
          this.dealRiskModal.setData({ ...data })
        }
      },
    })
    this.setState({
      dealRiskManageModalVisible: true
    })
  }
  //行车轨迹
  handleTrack = (record) => {
    sessionStorage.setItem("credit_track_vin", record.vin);
    const { formValues, pageObj } = this.state;
    this.props.dispatch(
      routerRedux.push({
        pathname: "/creditPlatform/creditCarTrack",
        state: { pageObj, formValues },
      })
    );
  };
  //风控日志
  changeriskLogModalVisible = (flag) => {
    if (flag) {
      this.setState({
        riskLogModalVisible: false,
      });
    } else {
      this.setState({
        riskLogModalVisible: false,
      });
    }
  };
  handleRiskLog = (record) => {
    this.setState({
      riskvin: record.vin,
      riskLogModalVisible: true,
    })
  }
  //通用配置
  handleConfig = () => {
    this.props.dispatch({
      type: 'creditCar/postObjWithRes',
      payload: {
        url: '/mscreditbusiness/vehicle/credit/search/move/config',
      },
      callback: (res) => {
        const { statusCode, data } = res;
        if (statusCode === '0') {
          this.configModal.showData(data)
        }
      },
    })
    // const data = {"whStorageTimeLimit": 1, "storageTimeLimit": 2, "moveTimeLimit": 3, "createBy":'zhang'}
    // this.configModal.showData(data)
  }
  //查看定位 ---待修改
  handleLocation = (vin) => {
    sessionStorage.setItem("vin", vin);
    sessionStorage.setItem("businessCode", "warn-vehicle-log");
    sessionStorage.setItem(
      "creditCarLocationbackPath",
      "/creditPlatform/creditCar"
    );
    this.props.dispatch(
      routerRedux.push({
        pathname:
          "/creditPlatform/creditCarLocation",
      })
    );
  };
  //锁车
  handleLockCar = (vin) => {
    this.props.dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/lock/set",
        vin: vin,
        businessCode: "credit-car-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("操作成功");
          this.handleTableNewData();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  //解除锁车
  handleUnlockCar = (vin) => {
    this.props.dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/lock/remove",
        vin: vin,
        businessCode: "credit-car-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("操作成功");
          this.handleTableNewData();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  //跛行
  handleLimp = (vin) => {
    this.props.dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/limp/set",
        vin: vin,
        businessCode: "credit-car-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("设置跛行成功");
          this.handleTableNewData();
        } else {
          message.error(response.statusMessage);
        }
      },
    });
  };
  //解除跛行
  handleUnlimp = (vin) => {
    this.props.dispatch({
      type: "creditCar/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/limp/remove",
        vin: vin,
        businessCode: "credit-car-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("操作成功");
          this.handleTableNewData();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  onRef = ref => {
    this.configModal = ref;
  };
  onMovingRef = ref => {
    this.movingModal = ref;
  };
  render() {
    const {
      tableData,
      batchSearchModalVisible,
      addModalVisible,
      batchImportModalVisible,
      bacthChangeStateModalVisible,
      exportTaskVisible,
      batchSelectData,
      total,
      tableLoading,
      curPage,
      pageSize,
      vin,
      seriesId,
      symbol,
      last7MileageStart,
      last7MileageEnd,
      merchantName,
      creditType,
      seriesList,
      bacthChangeStateModalData,
      exportLoading,
      batchAddTemplateFileUrl,
      batchSearchTemplateFileUrl,
      orgList,
      tboxRouseloading,
      tboxRouseCount,
      fieldList,
      tableColumns,
      visible,
      checked,
      riskLogModalVisible,
    } = this.state;
    const { menu: { permissions }, merchantsData } = this.props;
    const { location: { pathname } } = this.props;
    const isFinance = merchantsData.type !== 1; // 0 金融机构 1持车
    const batchimportBtnAuth = permissions.includes(pathname + '/' + 'creditCar_batchimport');//导入授信车辆
    const addBtnAuth = permissions.includes(pathname + '/' + 'creditCar_add');//新增授信车辆
    const exportCarBtnAuth = permissions.includes(pathname + '/' + 'creditCar_exportCar');//导出授信车辆
    const taskBtnAuth = permissions.includes(pathname + '/' + 'creditCar_exportTask');//任务中心
    const mapBtnAuth = permissions.includes(pathname + '/' + 'creditCar_searchCarMap');//地图查看授信车辆
    const stateBtnAuth = permissions.includes(pathname + '/' + 'creditCar_bacthChangeState') && isFinance;//批量修改授信车辆
    const configBtnAuth = permissions.includes(pathname + '/' + 'creditCar_config') && isFinance;//批量修改授信车辆;//通用配置，待修改
    const moveCarBthAuth = permissions.includes(pathname + '/' + 'creditCar_moveCar') && isFinance;//移车管理
    const riskLogBtnAuth = permissions.includes(pathname + '/' + 'creditCar_riskLog') && isFinance;//风控日志
    const pagination = {
      showSizeChanger: true,
      total: total,
      current: curPage,
      pageSize: pageSize,
      showTotal: () => {
        return <span>共&nbsp;{total}&nbsp;条</span>;
      },
    };
    const tboxBtn = {
      title: "操作",
      dataIndex: "操作",
      fixed: "right",
      align: "center",
      filterDropdown: (<div></div>),
      filterIcon: (
        <Tooltip placement="top" title="筛选">
          <SettingOutlined
            style={{ marginLeft: 1 }}
            onClick={() => this.openFieldModal()}
          />
        </Tooltip>
      ),
      render: (text, record) => {
        const locationBtnAuth = permissions.includes(pathname + '/' + 'creditCar_location');//查看定位
        const lockCarBtnAuth = permissions.includes(pathname + '/' + 'creditCar_lockCar');//锁车
        const limpBtnAuth = permissions.includes(pathname + '/' + 'creditCar_limp') && isFinance;//跛行
        const detailBtnAuth = permissions.includes(pathname + '/' + 'creditCar_detail') && isFinance;
        const tboxRouseBtnAuth = permissions.includes(pathname + '/' + 'creditCar_tboxRouse') && isFinance;
        const warnBtnAuth = permissions.includes(pathname + '/' + 'creditCar_warn') && isFinance;//车机告警  
        const { warnType, warnStatus } = record;//车机告警类型：0-不支持；  1-支持不可配置告警；2-支持可配置告警
        //车机告警状态： 告警状态:
        // 0-正常
        // 1-车机告警


        const isWarn =
          (warnBtnAuth) &&
          warnType != 0 &&
          ((warnType == 1 && record.overdueDays >= 1) || warnType == 2);
        // 持车机构不用按钮,但锁车时需能谈告警规则
        const isWarn1 =
          (!isFinance) &&
          warnType != 0 &&
          ((warnType == 1 && record.overdueDays >= 1) || warnType == 2);
        const btns = [];
        const detailBtn = {
          title: "详情",
          key: "detailBtn",
          onConfirm: () => this.handleDetail(record.vin),
        };
        let relieveBtnMessage = "是否确认解除授信，解除授信的车辆从授信车列表中删除?";
        if (record.riskStatus !== 0 && isFinance) {
          relieveBtnMessage = `当前车辆处于${riskStatusEnum[record.riskStatus]}状态，是否先解除${riskStatusEnum[record.riskStatus]}及告警提示再解除授信，解除授信的车辆将从授信车辆列表中删除`
        } else if (record.warnStatus === 1 && isFinance) {
          relieveBtnMessage = `当前车辆处于车机告警状态，是否先解除车机告警再解除授信，解除授信的车辆将从授信车辆列表中删除`
        }
        const relieveBtn = {
          title: "解除授信",
          Popconfirm: true,
          message: relieveBtnMessage,
          key: "relieve",
          onConfirm: () => this.handleRelieve(record.vin, record.warnStatus),
        };

        const tboxRouseBtn = {
          title: "TBOX唤醒",
          Popconfirm: true,
          message: "是否要对TBOX进行远程唤醒?",
          key: "tboxRouse",
          onConfirm: () => this.handleTboxRouse(record.vin),
        };
        const msgRulerBtn = {
          title: "车机告警",
          Popconfirm: true,
          message: "是否车机告警",
          key: "msgrulerBtn",
          onConfirm: () =>
            isWarn && warnType == 1
              ? this.handleWarnMsg(record)
              : this.handlemsgRulerList(record, 1),
        };
        const releaseRulertn = {
          title: "解除车机告警",
          Popconfirm: true,
          message: "是否解除车机告警",
          key: "msgremoverulerBtn",
          onConfirm: () => this.handlemsgRemove(record),
        };
        const movingCarBtn = {
          title: "移车管理",
          key: "movingCar",
          onConfirm: () => this.handleMovingcar(record),
        };
        const pathBtn = {
          title: "行车轨迹",
          key: "pathBtn",
          onConfirm: () => this.handleTrack(record),
        };
        const riskLogBtn = {//若手动或自动实施锁车/解除锁车/跛行/解除跛行后，则显示风控日志按钮   根据riskStatus判断，0--正常状态，不显示；1--锁车或跛行状态，需要显示
          title: "风控日志",
          key: "riskLogBtn",
          onConfirm: () => this.handleRiskLog(record),
        };
        const locationBtn = {
          title: "查看定位",
          key: "location",
          onConfirm: () => this.handleLocation(record.vin),
        };
        let lockMsg =
          record.riskStatus == 2
            ? "该车已处于跛行状态，是否解除跛行状态并实施锁车?"
            : "确认锁车吗?";

        let lockMsgAndWarn =
          record.riskStatus == 2
            ? "该车已处于跛行状态，是否解除跛行状态并实施锁车和车机告警吗?"
            : "确认锁车和车机告警吗?";
        const lockCarBtn = {
          title: "锁车",
          Popconfirm: true,
          message: isWarn && warnType == 1 ? lockMsgAndWarn : lockMsg,
          key: "lockCarBtn",
          onConfirm: () =>
            (isWarn || isWarn1) && warnType != 1
              ? this.handlemsgRulerList(record, 2)
              : this.handleLockCar(record.vin),
        };
        const unlockCarBtn = {
          title: "解除锁车",
          Popconfirm: true,
          message: "确认解锁车辆吗?",
          key: "unlockCarBtn",
          onConfirm: () => this.handleUnlockCar(record.vin),
        };
        let limpMsg =
          record.riskStatus == 1
            ? "该车已处于锁车状态，是否解除锁车状态并实施跛行？"
            : "确认设置跛行吗?";

        let limpMsgAndWarn =
          record.riskStatus == 1
            ? "该车已处于锁车状态，是否解除锁车状态并实施跛行和车机告警吗？"
            : "确认设置跛行和车机告警吗?";
        const limpBtn = {
          title: "跛行",
          Popconfirm: true,
          message: isWarn && warnType == 1 ? limpMsgAndWarn : limpMsg,
          key: "limp",
          onConfirm: () =>
            isWarn && warnType != 1
              ? this.handlemsgRulerList(record, 3)
              : this.handleLimp(record.vin),
        };
        const unlimpBtn = {
          title: "解除跛行",
          Popconfirm: true,
          message: "确认解除跛行吗?",
          key: "unlimp",
          onConfirm: () => this.handleUnlimp(record.vin),
        };
        btns.push(pathBtn);//行车轨迹
        if (record.riskStatus == 1 && riskLogBtnAuth) btns.push(riskLogBtn);//风控日志
        btns.push(relieveBtn);//解除授信
        //移车管理--授信类型为经销商
        if (record.creditType === 1 && moveCarBthAuth) {
          btns.push(movingCarBtn)
        }
        const limpEnable = record.limpEnable ?? 0;
        //0-不支持跛行
        if (limpEnable == 0 && record.riskStatus == 0) {//0-正常行驶
          if (detailBtnAuth) btns.push(detailBtn);
          if (locationBtnAuth) btns.push(locationBtn);
          if (lockCarBtnAuth) btns.push(lockCarBtn);
          if (record.tboxLostDays >= 1 && tboxRouseBtnAuth) btns.push(tboxRouseBtn);
        }
        if (limpEnable == 0 && record.riskStatus == 1) {//1-锁车
          if (detailBtnAuth) btns.push(detailBtn);
          if (locationBtnAuth) btns.push(locationBtn);
          if (lockCarBtnAuth) btns.push(unlockCarBtn);
          if (record.tboxLostDays >= 1 && tboxRouseBtnAuth) btns.push(tboxRouseBtn);
        }
        if (limpEnable == 0 && record.riskStatus == 2) {//2-跛行 持车机构无limpEnable字段
          if (detailBtnAuth) btns.push(detailBtn);
          if (locationBtnAuth) btns.push(locationBtn);
          if (lockCarBtnAuth) btns.push(lockCarBtn);
        }
        //1-支持跛行
        if (limpEnable == 1 && record.riskStatus == 0) {//0-正常行驶
          if (detailBtnAuth) btns.push(detailBtn);
          if (locationBtnAuth) btns.push(locationBtn);
          if (lockCarBtnAuth) btns.push(lockCarBtn);
          if (limpBtnAuth) btns.push(limpBtn);
          if (record.tboxLostDays >= 1 && tboxRouseBtnAuth) btns.push(tboxRouseBtn);
        }
        if (limpEnable == 1 && record.riskStatus == 1) {//1-锁车
          if (detailBtnAuth) btns.push(detailBtn);
          if (locationBtnAuth) btns.push(locationBtn);
          if (lockCarBtnAuth) btns.push(unlockCarBtn);
          if (limpBtnAuth) btns.push(limpBtn);
          if (record.tboxLostDays >= 1 && tboxRouseBtnAuth) btns.push(tboxRouseBtn);
        }
        if (limpEnable == 1 && record.riskStatus == 2) {//2-跛行
          if (detailBtnAuth) btns.push(detailBtn);
          if (locationBtnAuth) btns.push(locationBtn);
          if (lockCarBtnAuth) btns.push(lockCarBtn);
          if (limpBtnAuth) btns.push(unlimpBtn);
          if (record.tboxLostDays >= 1 && tboxRouseBtnAuth) btns.push(tboxRouseBtn);
        }
        if (isWarn) {
          if (warnStatus == 0) {
            btns.push(msgRulerBtn);
          } else {
            btns.push(releaseRulertn);
          }
        }
        return (
          <PateoAuthButtons
            authStr="creditCar"
            btns={btns}
          />
        );
      },
    };
    const tableProps = {
      // columns,
      columns: tableColumns.filter((i) => i.columnShow).concat([tboxBtn]),
      pagination,
      rowKey: "vin",
      scroll: { x: "max-content" },
      loading: tableLoading,
      dataSource: tableData,
      onChange: (pagination) => {
        this.setState(
          {
            curPage: pagination.current,
            pageSize: pagination.pageSize,
          },
          () => {
            this.handleTableNewData();
          }
        );
      },
      rowSelection: {
        selectedRowKeys: bacthChangeStateModalData,
        onChange: (selectedRowKeys, selectedRows) =>
          this.handleRowSelection(selectedRowKeys, selectedRows),
        getCheckboxProps: (record) => ({
          disabled:
            record.repaymentStatus === enums.repaymentStatus.expire.value,
        }),
      },
    };

    const rowSelection = {
      onChange: (selectedRowKeys, selectedRows) =>
        this.handleRowSelection(selectedRowKeys, selectedRows),
    };
    return (
      <Spin
        spinning={tboxRouseloading}
        size="large"
        tip={`Loading(${tboxRouseCount})s`}
      >
        <div>
          <div className={styles.pateoSearch}>
            <div className={styles.searchInputStr}>
              <div className={styles.title}>VIN号:</div>
              <Input
                placeholder="请输入vin号"
                value={vin}
                onChange={(e) => {
                  this.setState({
                    vin: e.target.value,
                  });
                }}
              />
              <Button onClick={() => this.handleBatchiSearch("batchSearch")}>
                批量
              </Button>
            </div>
            {
              merchantsData.type !== 1 ? <div className={styles.searchInputStr}>
                <div className={styles.title}>车辆所属公司:</div>
                <Select
                  value={merchantName}
                  placeholder="请选择车辆所属公司"
                  onChange={(e) => {
                    this.setState({
                      merchantName: e,
                    });
                  }}
                >
                  {orgList.map((org) => {
                    return (
                      <Option key={org.sid} value={org.sid}>
                        {org.name}
                      </Option>
                    );
                  })}
                </Select>
              </div> : null
            }
            <div className={styles.searchInputStr}>
              <div className={styles.title}>车系:</div>
              <Select
                placeholder="请选择车系"
                value={seriesId}
                onChange={(e) => {
                  this.setState({
                    seriesId: e,
                  });
                }}
              >
                {seriesList.map((series) => {
                  return (
                    <Option key={series.value} value={series.value}>
                      {series.label}
                    </Option>
                  );
                })}
              </Select>
            </div>
            {
              isFinance ? <div className={styles.searchInputStr}>
                <div className={styles.title}>最近7日行驶里程:</div>
                <Select
                  placeholder="请选择"
                  value={symbol}
                  onChange={(e) => {
                    this.setState({
                      symbol: e,
                      last7MileageStart: 0,
                      last7MileageEnd: 0,
                    });
                  }}
                >
                  {enums.comparison.array.map((option) => {
                    return (
                      <Option key={option.value} value={option.value}>
                        {option.label}
                      </Option>
                    );
                  })}
                </Select>
                {enums.comparison.gt.value === symbol ? (
                  <InputNumber
                    placeholder="请输入"
                    onChange={(e) => {
                      this.setState({
                        last7MileageStart: e || 0,
                      });
                    }}
                    value={last7MileageStart}
                    min={0}
                  />
                ) : null}
                {enums.comparison.between.value === symbol ? (
                  <>
                    <InputNumber
                      placeholder="请输入"
                      onChange={(e) => {
                        this.setState({
                          last7MileageStart: e || 0,
                        });
                      }}
                      value={last7MileageStart}
                      min={0}
                    />
                    <InputNumber
                      placeholder="请输入"
                      onChange={(e) => {
                        this.setState({
                          last7MileageEnd: e || 0,
                        });
                      }}
                      value={last7MileageEnd}
                      min={0}
                    />
                  </>
                ) : null}
                {enums.comparison.lt.value === symbol ? (
                  <InputNumber
                    placeholder="请输入"
                    onChange={(e) => {
                      this.setState({
                        last7MileageStart: e || 0,
                      });
                    }}
                    value={last7MileageStart}
                    min={0}
                  />
                ) : null}
              </div> : null
            }
            {
              merchantsData.type !== 1 ? <div className={styles.searchInputStr}>
                <div className={styles.title}>授信类型:</div>
                <Select
                  value={creditType}
                  placeholder="请选择授信类型"
                  onChange={(e) => {
                    this.setState({
                      creditType: e,
                    });
                  }}
                >
                  {transferOption(this.state.creditTypeOptions, ["value", "label"])}
                </Select>
              </div> : null
            }

            <div className={styles.searchBtn}>
              <Button
                style={{ marginRight: "10px" }}
                onClick={() => this.handleOpenSeachModal()}
              >
                更多筛选条件
              </Button>
              <Button
                onClick={() => this.handleSearch()}
                type={"primary"}
                style={{ marginRight: "10px" }}
              >
                查询
              </Button>
              <Button onClick={() => this.handleReset()}>重置</Button>
            </div>
          </div>
          <div className={styles.pateoBtns}>
            {batchimportBtnAuth
              ? (
                <div className={styles.btnItem}>
                  <Button
                    type="primary"
                    onClick={() => this.handleBatchimport("batchimport")}
                  >
                    批量导入授信车辆
                  </Button>
                </div>
              ) : null}
            {addBtnAuth
              ? (
                <div className={styles.btnItem}>
                  <Button type="primary" onClick={() => this.handleAdd("add")}>
                    新增授信车辆
                  </Button>
                </div>
              ) : null}
            {exportCarBtnAuth
              ? (
                <div className={styles.btnItem}>
                  <Button
                    loading={exportLoading}
                    type="primary"
                    onClick={() => this.handleExportCar("exportCar")}
                  >
                    导出授信车辆
                  </Button>
                </div>
              ) : null}
            {taskBtnAuth
              ? (
                <div className={styles.btnItem}>
                  <Button
                    type="primary"
                    onClick={() => this.handleExportTask("exportTask")}
                  >
                    任务中心
                  </Button>
                </div>
              ) : null}
            {mapBtnAuth
              ? (
                <div className={styles.btnItem}>
                  <Button
                    type="primary"
                    onClick={() => this.handleCreditCarMap()}
                  >
                    地图查看授信车辆
                  </Button>
                </div>
              ) : null}
            {configBtnAuth
              ? (
                <div className={styles.btnItem}>
                  <Button
                    type="primary"
                    onClick={() =>
                      this.handleConfig()
                    }
                  >
                    通用配置
                  </Button>
                </div>
              ) : null}
            {stateBtnAuth
              && batchSelectData.length > 0 ? (
              <div className={styles.btnItem}>
                <Button
                  type="primary"
                  onClick={() =>
                    this.handleBacthChangeState("bacthChangeState")
                  }
                >
                  批量修改授信车辆
                </Button>
              </div>
            ) : null}
            {(configBtnAuth || merchantsData.type === 1) && batchSelectData.length > 0
              ? (
                <div className={styles.btnItem}>
                  <Popconfirm
                    title="是否确认解除授信，并解除风控，从授信车列表中移除？"
                    onConfirm={this.bathRelieve}
                  >
                    <Button
                      type="primary"
                      danger
                    >
                      批量解除授信
                    </Button>
                  </Popconfirm>
                </div>
              ) : null}
          </div>

          <Card bordered={false} style={{ marginTop: 10 }}>
            <Table {...tableProps} />
          </Card>
          {batchSearchModalVisible ? (
            <BatchSearchModal
              templateFileUrl={batchSearchTemplateFileUrl}
              changeBatchSearchModalVisible={this.changeBatchSearchModalVisible}
            />
          ) : null}
          {addModalVisible ? (
            <AddModal
              orgList={orgList}
              creditTypeOptions={this.state.creditTypeOptions}
              fieldAdd={this.state.fieldAdd}
              specialData={this.specialDataGenrator()}
              changeAddModalVisible={this.changeAddModalVisible}
            />
          ) : null}
          {batchImportModalVisible ? (
            <BatchImportModal
              templateFileUrl={batchAddTemplateFileUrl}
              changeBatchImportModalVisible={this.changeBatchImportModalVisible}
            />
          ) : null}
          {bacthChangeStateModalVisible ? (
            <BacthChangeStateModal
              bacthChangeStateModalData={bacthChangeStateModalData}
              changeBacthChangeStateModalVisible={
                this.changeBacthChangeStateModalVisible
              }
            />
          ) : null}
          {exportTaskVisible ? (
            <ExportTaskModal
              changeExportTaskModalVisible={this.changeExportTaskModalVisible}
            />
          ) : null}
          <SearchAdtional
            onRef={(ref) => (this.SearchAdtionalRef = ref)} // ref赋值
            SearchAdtionalOptions={this.state.fieldMore} // 可选字段
            fieldName="credit"
            handleSubmit={(columns) => {
              // 点击确认搜索
              this.setState(
                {
                  fieldColumns: columns,
                  currentSearchMode: "2",
                },
                () => {
                  this.handleTableNewData();
                }
              );
            }}
          ></SearchAdtional>
          <FieldModal
            onRef={(fieldModal) => (this.fieldModal = fieldModal)}
            fieldName="credit"
            dispatch={this.props.dispatch}
            onSubmit={(tableColumns) => {
              this.setState({
                tableColumns,
              });
            }}
            tableColumns={tableColumns}
          />
          {this.state.msgRuleModalVisible && (
            <MsgRulerModal
              changeVisible={() => {
                this.setState({ msgRuleModalVisible: false });
                // this.handleTableNewData();
              }}
              onOk={() => {
                this.setState({ msgRuleModalVisible: false });
                this.handleTableNewData();
              }}
              businessCode="credit-car-log"
              visible={this.state.msgRuleModalVisible}
              ruleList={this.state.ruleList}
              ruleListType={this.state.ruleListType}
              record={this.state.ruleListSelectedRecord}
              dispatch={this.props.dispatch}
            />
          )}
          <MovingCarModal
            onRef={this.onMovingRef}
            dispatch={this.props.dispatch}
          />
          <DealerRiskManageModal
            changeVisible={() => {
              this.setState({ dealRiskManageModalVisible: false });
            }}
            modalVisible={this.state.dealRiskManageModalVisible}
            onRef={(dealRiskModal) => (this.dealRiskModal = dealRiskModal)}
            dispatch={this.props.dispatch}
          />
          {riskLogModalVisible ? (<RiskLogModal
            changeriskLogModalVisible={this.changeriskLogModalVisible}
            riskvin={this.state.riskvin}
          />) : null}
          <ConfigModal
            onRef={this.onRef}
            dispatch={this.props.dispatch}
          />
        </div>
      </Spin>
    );
  }
}
